package com.firstgroup.controller;

import com.firstgroup.domain.QuessionBank;
import com.firstgroup.service.Impl.QuestionBankServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@Api(tags = "题库类")
@RestController
@RequestMapping("/quession")
public class QuessionBankController {

    @Autowired
    QuestionBankServiceImpl quessionBankServiceImpl;

//    @ResponseBody
//    @RequestMapping(name = "/addQuession")
//    public String addQuession(String quessionName , String type, String answer){
//
//
//        return "123";
//    }

    /**
     * 遍历面试题库
     * @param
     * @return
     */
    @RequestMapping(value = "/findByInterview",method = RequestMethod.GET)
    @ApiOperation(value = "遍历面试题库")

    public List<QuessionBank> findByInterview(){
       List<QuessionBank> list= quessionBankServiceImpl.findByType("面试");
        System.out.println(list);
        return list;
    }

    /**
     * 遍历笔试题库
     * @return
     */
    @RequestMapping(value = "/findByWrite",method = RequestMethod.GET)
    @ApiOperation(value = "遍历笔试题库")
    public List<QuessionBank> findByWrite(){
        List<QuessionBank> list= quessionBankServiceImpl.findByType("笔试");
        System.out.println(list);
        return list;
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @RequestMapping(value = "/deleteById",method = RequestMethod.DELETE)
    @ApiOperation(value = "根据id删除题库，用于后台删除")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "题库id",name = "id",required = true,type = "int")

    })
    public Integer deleteById(int id){
     Integer list=  quessionBankServiceImpl.deleteQuession(id);
        return list;
    }

    /**
     * 遍历所有题库
     * @param
     * @return
     */

    @RequestMapping(value = "/findQuessions",method = RequestMethod.GET)
    @ApiOperation(value = "遍历出两种题库")
    public List<QuessionBank> findQuessions(){
    List<QuessionBank> list=    quessionBankServiceImpl.findQuessions();
        return  list;
    }

    /**
     * 根据id查询题库
     * @param id
     * @return
     */
    @RequestMapping(value = "/findById",method = RequestMethod.GET)
    @ApiOperation(value = "根据id查找题目")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "题库id",name = "id",required = true,type = "int")

    })
    public List<QuessionBank> findById(int id){
      List<QuessionBank> list= (List<QuessionBank>) quessionBankServiceImpl.findById(id);
        return list;

    }

    /**
     * 添加题库
     * @param quessionName,answer,type
     * @return
     */
    @RequestMapping(value = "/addQuessions",method = RequestMethod.POST)
    @ApiOperation(value = "添加题库功能")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "题目名称",name = "quessionName",required = true,type = "String"),
            @ApiImplicitParam(value = "题目答案（面试类型不用填写答案）",name = "answer",required = true,type = "String"),
            @ApiImplicitParam(value = "题目类型",name = "type",required = true,type = "String")

    })
    public QuessionBank addQuessions(String quessionName,String answer,String type){
        QuessionBank quessionBank=new QuessionBank();
        quessionBank.setQuessionName(quessionName);
        quessionBank.setAnswer(answer);
        quessionBank.setType(type);
        quessionBankServiceImpl.addQuession(quessionBank);
        return quessionBank;
    }

    /**
     * 修改题库
     * @param
     * @return
     */
    @RequestMapping(value = "/updateQuession",method = RequestMethod.PUT)
    @ApiOperation(value = "修改题库功能")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "题目名称",name = "quessionName",required = true,type = "String"),
            @ApiImplicitParam(value = "题目答案（面试类型不用填写答案）",name = "answer",required = true,type = "String"),
            @ApiImplicitParam(value = "题目类型",name = "type",required = true,type = "String")

    })
    public QuessionBank updateQuession(int id,String quessionName,String type,String answer){
       quessionBankServiceImpl.updateQuession(id, quessionName, type,answer);
        QuessionBank quessionBank=new QuessionBank();
        quessionBank.setQuessionName(quessionName);
        quessionBank.setAnswer(answer);
        quessionBank.setType(type);
        return quessionBank;

    }

}
